<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="患者姓名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入患者姓名"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" :display="true" @changeType="changeDisplay" @queryTable="getList"></right-toolbar>
    </el-row>
    <div v-if="display==='list'">
      <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="就诊编号" align="center" prop="code" width="150"/>
        <el-table-column label="真实姓名" align="center" prop="username" />
        <el-table-column label="性别" align="center" prop="gender" width="60" />
        <el-table-column label="年龄" align="center" prop="age" width="60"/>
        <el-table-column label="手机号" align="center" prop="phone" />
        <el-table-column label="状态" align="center" prop="state">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.wx_user_state" :value="scope.row.state"/>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ moment(scope.row.createTime).format('YYYY-MM-DD') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="operation(scope.row)"
              v-hasPermi="['wx:user:query']"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-else>
      <el-row :gutter="6">
        <el-col :span="8" v-for="(item, index) in userList" :key="index">
          <el-card shadow="hover">
            <div class="content-main">
              <img :src="item.avatar ? avatar : 'https://jywk.wingstimes.com/prod-api/profile/avatar/2023/07/12/blob_20230712145046A001.png'" class="user-avatar">
              <div class="content-text">
                <div class="user-name">{{ item.username }}</div>
                <div class="param-box">
                  <div class="param">
                    <div class="label">患者编号</div>
                    <div class="value">{{item.code}}</div>
                  </div>
                  <div class="param">
                    <div class="label">患者手机号</div>
                    <div class="value">{{item.phone}}</div>
                  </div>
                </div>
              </div>
            </div>
          </el-card>
          <div class="button-group">
            <button :disabled="checkPermi(['wx:user:query'])===true?false:true" @click="operation(item)"><i class="el-icon-view"></i>查看</button>
          </div>
        </el-col>
      </el-row>

    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :page-sizes="pageSizes"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
    import { listUser, getUser, delUser, addUser, updateUser } from "@/api/wechat/user";
    import {checkPermi} from "../../../utils/permission";

    export default {
        name: "processedUser",
        dicts: ['wx_user_state','sys_user_sex'],
        data() {
            return {
                pageSizes:[12,24,36],
                value: true,
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 字典表格数据
                userList: [],
                // 日期范围
                dateRange: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 12,
                    username: undefined,
                    password: undefined,
                    phone: undefined,
                    state: 1
                },
                display: 'list',
            };
        },
        created() {
            this.getList();
        },
        activated() {
            this.getList();
        },
        methods: {
            /** 查询患者列表 */
            getList() {
                this.loading = true;
                listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
                        this.userList = response.rows;
                        this.total = response.total;
                        this.loading = false;
                    }
                );
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.queryParams.state = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = [];
                this.resetForm("queryForm");
                this.handleQuery();
            },
            /** 多选框选中数据 */
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.userId)
                this.single = selection.length!=1
                this.multiple = !selection.length
            },

            /** 操作 */
            operation(row){
                const userId = row.userId;
                this.$router.push("/wxchat/record/viewInfo/" + userId);
            },
            changeDisplay(value){
                this.display = value
                console.log(value)
            }
        }
    };
</script>
<style lang="scss" scoped>
  .el-col{
    margin-top: 10px;
  }
  .content-main{
    display: flex;
    flex-direction: row;
    .user-avatar{
      width: 100px;
      height: 100px;
      border-radius: 15px;
      margin: 10px;
    }
    .content-text{
      display: flex;
      flex-direction: column;
      padding: 10px;
      .user-name{
        font-size: 24px;
        font-weight: bold;
      }
      .param-box{
        display: flex;
        flex-direction: row;
        margin-top: 15px;
        .param{
          margin-right: 30px;
          .label{
            margin-bottom: 10px;
            color: #5a5e66;
          }
          &:last-child {
            margin-right: 0;
          }
        }
      }
    }
  }
  .button-group{
    width: 100%;
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    button{
      width: 100%;
      height: 35px;
      font-size: 17px;
      background-color: #f6f6f6;
      border: 1px solid #e6e6e6;
      color: #409EFF;
      i{
        margin-right: 10px;
      }
    }
    button:disabled{
      pointer-events: none;
      cursor: not-allowed;
      color: #f6f6f6;
      background-color: #e6e6e6;
    }

    button:hover{
      color: #f6f6f6;
      background-color: #409EFF;

    }
  }


</style>
